package adminController

import (
	"fmt"
	"net/http"
	apiModel "westarry/gin-fox/app/api/model"
	. "westarry/gin-fox/app/base"
	. "westarry/gin-fox/gin-fox"
	. "westarry/gin-fox/gin-fox/router"

	"github.com/gin-gonic/gin"
)

var model apiModel.User
var userFieldList = []string{
	"id",
	"username",
}

func init() {
	RegisterController(&user{
		NoNeedRight: []string{
			"userInfo",
		},
		NoNeedLogin: []string{
			"*",
		},
		ReqMethod: map[string]string{
			"index":     "GET",
			"list":      "GET",
			"add":       "POST",
			"edit":      "POST",
			"del":       "POST",
			"fieldList": "GET",
		},
	})
}

type user struct {
	BaseController
	NoNeedLogin []string
	NoNeedRight []string
	AllowFields []string
	ReqMethod   map[string]string
}

func (_self *user) UserInfo(c *gin.Context) {
	model := apiModel.User{}
	model.GetOne(&model, 1)
}
func (_self *user) List(c *gin.Context) {
	list := model.Pager(Gc.D.Model(model).Select(userFieldList), c)
	fmt.Println(list)
	Gc.U.Success(list, "成功", c)
}
func (_self *user) FieldsList(c *gin.Context) {

}
func (_self *user) Index(c *gin.Context) {
	c.HTML(http.StatusOK, "user/index.html", gin.H{})
}
